<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<title>Index</title>

<jsp:include page="../header.jsp"></jsp:include>

<script type="text/javascript">
	$(function() {
		$("#addChatBot").click(function() {
			showChatBotPanel();
		});

        $('.selectpicker').selectpicker();
	});

	function showChatBotPanel(id, name, groupList, webhook) {
		$("#chatBotPanel [name='chatBot.id']").val(id);
		$("#chatBotPanel [name='chatBot.name']").val(name);
		$("#chatBotPanel [name='chatBot.groupList']").val(groupList);
		$("#chatBotPanel [name='chatBot.webhook']").val(webhook);
        $("#chatBotPanel").modal();
	}
</script>
</head>
<body>
	<jsp:include page="../top.jsp"></jsp:include>

	<div class="container theme-showcase" role="main">

		<div class="alert alert-success">
			<h2>群聊机器人列表</h2>
		</div>
		<div class="well">
			<div>
				<a class="btn btn-success" id="addChatBot">添加机器人</a>
			</div>
		</div>

		<div id="chatBotList">
			<table class="table table-hover">
				<tr>
					<th>名称</th>
					<th>群组列表</th>
					<th>webhook</th>
					<th>操作</th>
				</tr>
				<s:iterator value="chatBotList" var="d">
					<tr>
						<td><s:property value="#d.name" /></td>
						<td><s:property value="#d.groupList" /></td>
						<td><s:property value="#d.webhook" /></td>
						<td>
							<div class="btn-group" role="group">
								<button type="button" class="btn btn-primary dropdown-toggle"
									data-toggle="dropdown" aria-haspopup="true"
									aria-expanded="false">
									操作 <span class="caret"></span>
								</button>
								<ul class="dropdown-menu">
									<li><a href="javascript:void(0);"
										onclick="showChatBotPanel('<s:property value="#d.id"/>','<s:property value="#d.name"/>','<s:property value="#d.groupList"/>','<s:property value="#d.webhook"/>');">修改</a></li>
									<li role="separator" class="divider"></li>
									<li><a
										href="chatBot/deleteChatBot?chatBot.id=<s:property value='#d.id'/>" onclick="return confirm('确认删除吗？');">删除</a></li>
								</ul>
							</div>
						</td>
					</tr>
				</s:iterator>
			</table>
		</div>
		<div class="modal fade" id="chatBotPanel" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<form action="chatBot/saveChatBot" method="post">
				<input type="hidden" name="chatBot.id" />
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title">群聊机器人信息</h4>
						</div>
						<div class="modal-body">
							<h4>
								<ul class="list-group">
									<li class="list-group-item"><label> 名称 </label> <input
										type="text" class="form-control" name="chatBot.name"
										placeholder="名称" /></li>
									<li class="list-group-item"><label> 群组列表 </label> <input
										type="text" class="form-control" name="chatBot.groupList"
										placeholder="群组列表" /></li>
									<li class="list-group-item"><label> webhook </label> <input
											type="text" class="form-control" name="chatBot.webhook"
											placeholder="webhook" /></li>
								</ul>
							</h4>
						</div>
						<div class="modal-footer">
							<button type="submit" class="btn btn-success">保存</button>
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
	<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>
